package edu.arizona.eller.mis.liferoulette.utils;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class LocUtility{

	private LocationManager locManager;
	private String locationprovider;
	private Location currentLocation;
	private Criteria criteria;
	
	LocationListener locListener;
	
	public LocUtility(){}
	
	public LocUtility(LocationManager locationManager){
		super();
		this.locManager = locationManager;
		
		criteria = new Criteria();
		criteria.setAccuracy(Criteria.ACCURACY_FINE);
		criteria.setPowerRequirement(Criteria.POWER_LOW);
		
		locationprovider = this.locManager.getBestProvider(criteria, true);
		currentLocation = this.locManager.getLastKnownLocation(locationprovider);
		//or "gps"?
	}
	
	public Location getCurrentLoc(){
		locListener = new LocationListener() {
			public void onStatusChanged(String provider, int status,Bundle extras) {}
			public void onLocationChanged(Location location) {
				currentLocation = location;
			}
			public void onProviderDisabled(String provider) {}
			public void onProviderEnabled(String provider) {}
		};
		locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
		return currentLocation;
	}
}
